home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-13 | 1.5 KB | 63 lines | [TEXT/MPS ] |
- /*************************************************************************************
- *
- * Apply a ShellSort algorithm to an offscreen, scrambled GWorld
- *
- * ShellSort.cp - C Source
- *
- * Copyright © Apple Computer, Inc. 1988 - 1993
- * All rights reserved.
- *
- * This is the "guts" of the SortPicts program. This file performs the actual
- * sort algorithm which gives the image its restoration quality (restoring itself
- * to its original self).
- *
- *************************************************************************************/
- #include "SortPicts.h"
-
- void ShellSort( SortPicts *sortPicts)
- {
- sortPicts->ShellSort();
- }
-
- /*************************************************************/
- /* */
- /* The Actual Sort Algorithms */
- /* */
- /*************************************************************/
-
-
- void SortPicts :: ShellSort( void)
- {
- long loop, sortSize, inLoop;
- long min;
- long data;
-
- sortSize = 1;
- while( sortSize < N)
- sortSize = 3 * sortSize + 1;
-
- do
- {
- sortSize /= 3;
- for( loop = sortSize; loop < N; ++loop)
- {
- min = sortData[loop];
-
- for( inLoop = loop; (data = sortData[inLoop - sortSize]) > min; )
- {
- SetSortItem( inLoop, data);
-
- inLoop -= sortSize;
- if( inLoop < sortSize)
- break;
- }
-
- SetSortItem( inLoop, min);
- }
-
- } while( sortSize > 0); // 1 = cool picts; 0 = actual sort
- }
-
-
-
-